package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.manage.domain.db.Settings;
import com.tanhua.dubbo.mapper.SettingsMaper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class SettingsApiImpl implements SettingsApi{

    @Autowired
    private SettingsMaper settingsMaper;

    /**
     * 查询通用设置列表
     * @return
     */
    @Override
    public Settings findByUserId(Long userId) {
        QueryWrapper<Settings> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        return settingsMaper.selectOne(queryWrapper);
    }

    /**
     * 保存通知设置
     * @param settings
     */
    @Override
    public void save(Settings settings) {
        Settings settingsInDB = findByUserId(settings.getUserId());
        if (null != settingsInDB){
            settings.setId(settingsInDB.getId());
            settingsMaper.updateById(settings);
        }else{
        settingsMaper.insert(settings);
        }
    }
}
